'use strict';

var moment = require('moment');

module.exports = app => {
  const {
    INTEGER,
    STRING,
    DATE,
  } = app.Sequelize;

  const User = app.model.define('users', {
    uid: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    mobilePhone: {
      type: STRING
    },
    openId: {
      type: STRING
    },

    username: {
      type: STRING
    },
    avatarUrl: {
      type: STRING,
      allowNull: true
    },
    gender: {
      type: INTEGER,
      allowNull: true
    },
    state: {
      type: INTEGER,
      defaultValue: 1
    },
    
    created_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('created_at')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    updated_at:  {
      type: DATE,
      get() {
        return moment(this.getDataValue('updated_at')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
  });

  User.associate = function() {
    // app.model.User.hasMany(app.model.Comment);
    // app.model.User.hasMany(app.model.Topic);
  };

  return User;
};